class Animal{
    private String name;
    private int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
    public void eat(){
        System.out.println(this.getName() + "吃食物");
    }
    public void barks(){
        System.out.println(this.getName()+"叫");
    }
 }
 class Dog extends Animal{
     public Dog(String name, int age) {
         super(name, age);
     }
     public void eat(){
         System.out.println(this.getName() + "吃狗粮");
     }


     public void barks() {
         System.out.println(this.getName()+"汪汪");
     }

 }
public class Test1 {
    public static void func(Animal a){//方法传参：形参为父类型引用，可以接收任意子类的对象
        a.eat();
    }
    public static Animal func1(int a){
        if(a == 1){
            return new Dog("白糖",3);
        }else{
            return null;
        }
    }
    public static void main(String[] args) {
     Dog d = new Dog("大飞",4);
     func(d);
     Animal a = func1(1);
     a.barks();
    }
}
